﻿using LdtDataEngin.ModuleDetail.BaseModule;
using LdtDataEngin.ModuleDetail.BaseModule.MultiFack;
using LdtJudge.DataEngine.Model.DataModel.SysCommon;
using LdtJudge.DataEngine.Model.ElmentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LdtDataEngin.ModuleDetail.AnalysisModule.CaseCauseElementExtr
{
    /// <summary>
    /// 结果要素提取
    /// </summary>
    public class ResultInfoElement : FactElementBaseClass
    {
        #region 基础信息
        /// <summary>
        /// 案由信息
        /// </summary>
        public CaseCauseModel SYS_CaseCause { get; set; }
        /// <summary>
        /// 父节点信息
        /// </summary>
        public CaseCauseModel mSYS_CaseCause { get; set; }

        #endregion

        /// <summary>
        /// 新程序要素提取入口
        /// </summary>
        /// <param name="onExtract"></param>
        /// <param name="nodeModelList"></param>
        /// <returns></returns>
        public override XmlNode ExtElementXmlParse(OnExtractComplete onExtract, NodeModelList nodeModelList)
        {
            List<NodeModel> listNodeModel = new List<NodeModel>();
            CommElementRegexCode commElementRegexCode = new CommElementRegexCode();
            commElementRegexCode.CaseType = _dataContext.DataLayerAns.CaseType;
            commElementRegexCode.SourceCode = _dataContext.DataLayerAns.SourceCode;
            commElementRegexCode.TextType = Convert.ToInt32(_dataContext.DataLayerAns.TextType);
            var groupparsetext = GroupParseTextDic.Where(a=> resultParagraphList.Contains(a.Key.ParagraphCode.ToLower())).ToList();
            foreach (var item in groupparsetext)
            {
                commElementRegexCode.PargarphCode = item.Key.ParagraphCode;
                commElementRegexCode.Purpose = ExtractType.jieguoyaosu;
                Dictionary<string, List<string>> ParagraphTemp = new Dictionary<string, List<string>>();
                ParagraphTemp.Add(item.Key.ParagraphCode.ToLower(), new List<string>() { item.Value });
                messagelist = new List<string>();
                ///清空源数据
                base.OriginalTextNodeList.Clear();
                base.LoadeNodeModel(null, mSYS_CaseCause, listNodeModel, item.Value, ParagraphTemp, commElementRegexCode);

                if (listNodeModel.Count > 0)
                {
                    ///将提取一次的数据进行存入到提取前数据集合中
                    nodeModelList.BeforeMergerListModels.AddRange(base.OriginalTextNodeList);
                    nodeModelList.BeforeMergerListModels.AddRange(listNodeModel);
                }
                onExtract(commElementRegexCode.Purpose, listNodeModel, messagelist, item.Key);
            }
            ModelXmlHandle modelXmlHandle = new ModelXmlHandle() { };
            modelXmlHandle.dataContext = _dataContext;
            XmlNode xml = modelXmlHandle.ModelToXmlPro(SYS_CaseCause, listNodeModel);
            return xml;
        }
    }
}
